package com.ruoyi.peopleinfo.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.peopleinfo.domain.PeopleHealth;
import com.ruoyi.peopleinfo.service.IPeopleHealthService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 健康信息Controller
 *
 * @author y
 * @date 2022-02-26
 */
@RestController
@RequestMapping("/peopleinfo/health")
public class PeopleHealthController extends BaseController
{
    @Autowired
    private IPeopleHealthService peopleHealthService;

    /**
     * 查询健康信息列表
     */
    @PreAuthorize("@ss.hasPermi('peopleinfo:health:list')")
    @GetMapping("/list")
    public TableDataInfo list(PeopleHealth peopleHealth)
    {
        startPage();
        List<PeopleHealth> list = peopleHealthService.selectPeopleHealthList(peopleHealth);
        return getDataTable(list);
    }

    /**
     * 导出健康信息列表
     */
    @PreAuthorize("@ss.hasPermi('peopleinfo:health:export')")
    @Log(title = "健康信息", businessType = BusinessType.EXPORT)
    //导出健康信息列表
    @PostMapping("/export")
    public void export(HttpServletResponse response, PeopleHealth peopleHealth)
    {
        List<PeopleHealth> list = peopleHealthService.selectPeopleHealthList(peopleHealth);
        ExcelUtil<PeopleHealth> util = new ExcelUtil<PeopleHealth>(PeopleHealth.class);
        util.exportExcel(response, list, "健康信息数据");
    }

    /**
     * 获取健康信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('peopleinfo:health:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(peopleHealthService.selectPeopleHealthById(id));
    }

    /**
     * 新增健康信息
     */
    @PreAuthorize("@ss.hasPermi('peopleinfo:health:add')")
    @Log(title = "健康信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PeopleHealth peopleHealth)
    {
        return toAjax(peopleHealthService.insertPeopleHealth(peopleHealth));
    }

    /**
     * 修改健康信息
     */
    @PreAuthorize("@ss.hasPermi('peopleinfo:health:edit')")
    @Log(title = "健康信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PeopleHealth peopleHealth)
    {
        return toAjax(peopleHealthService.updatePeopleHealth(peopleHealth));
    }

    /**
     * 删除健康信息
     */
    @PreAuthorize("@ss.hasPermi('peopleinfo:health:remove')")
    @Log(title = "健康信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(peopleHealthService.deletePeopleHealthByIds(ids));
    }
}
